import * as staticDict from '@/staticDict';

export default class DictionaryController {
  static dictSysRole(sender, params, axiosOption, httpOption) {
    return new Promise((resolve, reject) => {
      sender
        .doUrl('admin/upms/sysRole/listDict', 'get', params, axiosOption, httpOption)
        .then(res => {
          let dictData = new staticDict.DictionaryBase('角色字典');
          dictData.setList(res.data);
          resolve(dictData);
        })
        .catch(err => {
          reject(err);
        });
    });
  }

  static dictLayerFeatureType() {
    return new Promise((resolve) => {
      resolve(staticDict.LayerFeatureType);
    });
  }
  // 全局编码字典
  static dictGlobalDict(sender, params, axiosOption, httpOption) {
    return new Promise((resolve, reject) => {
      sender
        .doUrl('admin/upms/globalDict/listDict', 'get', params, axiosOption, httpOption)
        .then(res => {
          let dictData = new staticDict.DictionaryBase('编码字典');
          dictData.setList(
            (res.data || []).map(item => {
              return {
                ...item,
                // 设置已禁用编码字典数据项
                disabled: item.status === 1
              };
            })
          );
          resolve(dictData);
        })
        .catch(err => {
          reject(err);
        });
    });
  }

  static dictGlobalDictByIds(sender, params, axiosOption, httpOption) {
    return new Promise((resolve, reject) => {
      sender
        .doUrl('admin/upms/globalDict/listDictByIds', 'get', params, axiosOption, httpOption)
        .then(res => {
          let dictData = new staticDict.DictionaryBase('编码字典');
          dictData.setList(res.data);
          resolve(dictData);
        })
        .catch(err => {
          reject(err);
        });
    });
  }

  static dictSysUserStatus() {
    return new Promise(resolve => {
      resolve(staticDict.SysUserStatus);
    });
  }
  static dictSysUserType() {
    return new Promise(resolve => {
      resolve(staticDict.SysUserType);
    });
  }
  static dictYesNoDict() {
    return new Promise(resolve => {
      resolve(staticDict.YesNoDict);
    });
  }
  static dictCustomValidateRuleDict() {
    return new Promise(resolve => {
      resolve(staticDict.CustomValidateRule);
    });
  }
  static dictCustomControlTypeDict() {
    return new Promise(resolve => {
      resolve(staticDict.CustomControlType);
    });
  }
  static dictAreaCode(sender, params, axiosOption, httpOption) {
    return new Promise((resolve, reject) => {
      sender
        .doUrl('/admin/app/areaCode/listDict', 'get', params, axiosOption, httpOption)
        .then(res => {
          let dictData = new staticDict.DictionaryBase('区划字典');
          dictData.setList(res.data);
          resolve(dictData);
        })
        .catch(err => {
          reject(err);
        });
    });
  }
  static dictSysDept(sender, params, axiosOption, httpOption) {
    return new Promise((resolve, reject) => {
      sender
        .doUrl('/admin/upms/sysDept/listDict', 'get', params, axiosOption, httpOption)
        .then(res => {
          let dictData = new staticDict.DictionaryBase('部门字典');
          dictData.setList(res.data);
          resolve(dictData);
        })
        .catch(err => {
          reject(err);
        });
    });
  }
  static dictSysDeptByParentId(sender, params, axiosOption, httpOption) {
    return new Promise((resolve, reject) => {
      sender
        .doUrl('/admin/upms/sysDept/listDictByParentId', 'get', params, axiosOption, httpOption)
        .then(res => {
          let dictData = new staticDict.DictionaryBase('部门字典');
          dictData.setList(res.data);
          resolve(dictData);
        })
        .catch(err => {
          reject(err);
        });
    });
  }
  static dictProjectTemplate(sender, params, axiosOption, httpOption) {
    return new Promise((resolve, reject) => {
      sender
        .doUrl('/admin/app/projectTemplate/list', 'post', params, axiosOption, httpOption)
        .then(res => {
          let dictData = new staticDict.DictionaryBase('项目模板字典');
          dictData.setList(res.data.dataList, 'id', 'name');
          resolve(dictData);
        })
        .catch(err => {
          reject(err);
        });
    });
  }
  static dictAllMenu(sender, params, axiosOption, httpOption) {
    return new Promise((resolve, reject) => {
      sender
        .doUrl('admin/upms/sysMenu/listDict', 'get', params, axiosOption, httpOption)
        .then(res => {
          let dictData = new staticDict.DictionaryBase('菜单字典');
          dictData.setList(res.data);
          resolve(dictData);
        })
        .catch(err => {
          reject(err);
        });
    });
  }
  static dictSysMenu(sender, params, axiosOption, httpOption) {
    return new Promise((resolve, reject) => {
      sender
        .doUrl('admin/upms/sysMenu/listMenuDict', 'get', params, axiosOption, httpOption)
        .then(res => {
          let dictData = new staticDict.DictionaryBase('菜单字典');
          dictData.setList(res.data);
          resolve(dictData);
        })
        .catch(err => {
          reject(err);
        });
    });
  }
  static dictPmDict (sender, params, axiosOption, httpOption) {
    return new Promise((resolve, reject) => {
      sender.doUrl('/admin/app/pmDictType/listDict', 'get', params, axiosOption, httpOption).then(res => {
        let dictData = new staticDict.DictionaryBase('数据字典');
        dictData.setList(res.data);
        resolve(dictData);
      }).catch(err => {
        reject(err);
      });
    });
  }
  static dictPmDictData (sender, params, axiosOption, httpOption) {
    return new Promise((resolve, reject) => {
      sender.doUrl('/admin/app/pmDictData/listDict', 'get', params, axiosOption, httpOption).then(res => {
        let dictData = new staticDict.DictionaryBase('字典数据');
        dictData.setList(res.data);
        resolve(dictData);
      }).catch(err => {
        reject(err);
      });
    });
  }
}
